import { userListApi, userListLikeApi } from '@/api/user'
export default {
    state: {
        userList: {},
    },
    mutations: {
        saveUserList(state, userList) {
            if (userList.data instanceof Array) {
                userList.data.forEach(i => {
                    i.is_show = Boolean(i.is_show - 0)
                    i.is_delete = Boolean(i.is_delete - 0)
                });
            }
            state.userList = userList
        }
    },
    actions: {
        async saveUserList(context, option) {
            try {
                const result = await userListApi(option)
                context.commit('saveUserList', result.data.data.data)
            } catch (e) {
                console.log(e.response);
            }
        },
        async saveUserListLike(context, option) {
            try {
                const result = await userListLikeApi(option)
                result.data.data.data.userListLike = { flag: true, status: result.data.data.data.data.length > 0 ? "ok" : "missing" }
                context.commit('saveUserList', result.data.data.data)
            } catch (error) {
                console.log(error.response);
            }
        },
    },
}